package com.blb.eduorderservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blb.common.entity.UserCourseOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderMapper extends BaseMapper<UserCourseOrder> {
    /**
     * 修改订单状态
     * @param tradeNo
     * @param status
     */
    @Update("update user_course_order set status = #{status} where trade_no = #{tradeNo}")
    void updateOrderStatus(@Param("tradeNo") String tradeNo, @Param("status") long status);

    /**
     * 查询用户订单
     * @param userId
     * @return
     */
    @Select("select * from user_course_order where user_id = #{userId}")
    List<UserCourseOrder> selectOrdersByUserId(@Param("userId") long userId);

    /**
     * 查询订单号订单
     * @return
     */
    @Select("select * from user_course_order where trade_no = #{tradeNo}")
    UserCourseOrder selectOrderByTradeNo(@Param("tradeNo") String tradeNo);

    /**
     * 插入到订单表
     * @param order
     */
    @Insert("insert into user_course_order(user_id,course_id,activity_id,pay_type_id,trade_no,price,status,is_del)\n" +
            "  values(#{userId},#{courseId},#{activityId},#{payTypeId},#{tradeNo},#{price},#{status},#{isDel})")
    void insertOrder(UserCourseOrder order);

    /**
     * 分页查询
     * @param from
     * @param size
     * @return
     */
    @Select("select * from user_course_order order by id limit #{from},#{size} ")
    List<UserCourseOrder> selectOrderLimit(long from,long size);

}
